Use case: Read and write operations

Sequence diagram

Read and write operations

@startuml

== Prerequisite: Initialization and configuration ==

== Process ==

"User Application" -> "HAL SRAM Driver" : HAL_SRAM_Write_xx()
note right: **Write operation**
"HAL SRAM Driver" --> "User Application": hal status : HAL_OK or HAL_ERROR
note right: **Return**

"User Application" -> "HAL SRAM Driver" : HAL_SRAM_Read_xx()
note right: **Read operation**
"HAL SRAM Driver" --> "User Application" : hal status : HAL_OK or HAL_ERROR
note right: **Return**

@enduml

Code snippet

HAL1

HAL2

/* - */



// Write data to the SRAM memory
HAL_SRAM_Write_8b(&hsram,
                   (uint32_t *)(target_address),
                   data_to_write,
                   BufferSize
                  );

// Read data from the SRAM memory
HAL_SRAM_Read_8b(&hsram,
                  (uint32_t *)(target_address),
                  data_read,
                  BufferSize
                 );
uint32_t size;
uint8_t *psramaddress = (uint8_t *)target_address;
uint8_t *psrcbuff = data_to_write;
uint8_t *pdestbuff = data_read;
/* Write data to memory */
for (size = BufferSize; size != 0U; size--)
{
   *psramaddress = *psrcbuff;
   psrcbuff++;
   psramaddress++;
}
/* Read data from memory */
for (size = BufferSize; size != 0U; size--)
{
   *pdestbuff = *psramaddress;
   pdestbuff++;
   psramaddress++;
}

Key changes

  1. In HAL2, the SRAM driver only configures FMC; there are no dedicated SRAM read/write APIs.

  2. Once FMC is configured, SRAM is memory-mapped and accessed by direct CPU reads/writes.